package com.hd.view.action;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.hd.common.Common;
import com.hd.common.DataPage;
import com.hd.persistence.model.ActualizeProject;
import com.hd.persistence.model.Customer;
import com.hd.persistence.model.Machine;
import com.hd.persistence.model.PartUsage;
import com.hd.persistence.model.Person;
import com.hd.persistence.model.PurchaseRecord;
import com.hd.persistence.model.RepairReport;

/**
 * 维修单Action
 * @author jiaoyang
 *
 */
public class ProtectAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private RepairReport repairReport;
	/*客户名*/
	private List<Customer> customers;
	/*机型*/
	private List<Machine> machines;
	/*作业人员*/
	private List<Person> maintenanceMen;
	/*维修日期*/
	private String repairDate;
	/*维修的机器序号*/
	private String machineNo;
	/*查询出的维修单*/
	private DataPage<RepairReport> repairReports;
	
	/*================使用零件==================*/
	private PartUsage partUsage1;
	private PartUsage partUsage2;
	private PartUsage partUsage3;
	private PartUsage partUsage4;
	private PartUsage partUsage5;
	private PartUsage partUsage6;
	private PartUsage partUsage7;
	private PartUsage partUsage8;
	
	/*===============实施项目======================*/
	private ActualizeProject actualizeProject1;//光学部分
	private ActualizeProject actualizeProject2;//感光鼓
	private ActualizeProject actualizeProject3;//激光头
	private ActualizeProject actualizeProject4;//传动部分
	private ActualizeProject actualizeProject5;//结构部件
	private ActualizeProject actualizeProject6;//扫描架
	private ActualizeProject actualizeProject7;//显影器
	private ActualizeProject actualizeProject8;//定影部分
	private ActualizeProject actualizeProject9;//传动齿轮
	private ActualizeProject actualizeProject10;//鼓总成
	private ActualizeProject actualizeProject11;//载体
	private ActualizeProject actualizeProject12;//上下分离爪
	private ActualizeProject actualizeProject13;//各点电压
	private ActualizeProject actualizeProject14;//送稿器
	private ActualizeProject actualizeProject15;//机腔内
	private ActualizeProject actualizeProject16;//回收器
	private ActualizeProject actualizeProject17;//上下绲
	private ActualizeProject actualizeProject18;//打印卡
	private ActualizeProject actualizeProject19;//充电转印
	private ActualizeProject actualizeProject20;//纸道
	private ActualizeProject actualizeProject21;//传感器
	private ActualizeProject actualizeProject22;//加粉装置
	private ActualizeProject actualizeProject23;//搓纸轮
	private ActualizeProject actualizeProject24;//传真卡
	private ActualizeProject actualizeProject25;//控制板/零件
	private ActualizeProject actualizeProject26;//双面/装订器
	private ActualizeProject actualizeProject27;//曝光/定影灯
	private ActualizeProject actualizeProject28;//墨粉/粉组件
	private ActualizeProject actualizeProject29;//刮板
	private ActualizeProject actualizeProject30;//转印带挂板
	/**
	 * 增加新的维修单
	 * 
	 * @return
	 * @throws Exception
	 */
	public String addNewProtect() throws Exception{
		/*列出所有客户*/
		customers = purchaseManager.listCustomers();
		/*列出所有维修员*/
		maintenanceMen = memberManager.listPerson(2,false);
		/*列出所有机器*/
		machines = memberManager.listMachine();
		return SUCCESS;
	}
	
	/**保存维修单
	 * @return
	 * @throws Exception
	 */
	public String saveProtect() throws Exception{
		PurchaseRecord purchaseRecord = purchaseManager.findPurchaseRecordBy(machineNo);
		repairReport.setCustomerId(purchaseRecord.getCustomer().getCustomerId());
		repairReport.setMachineNo(machineNo);
		repairReport.setPurchaseRecord(purchaseRecord);
		repairReport.setRepairDate(Common.String2Date(repairDate));
		repairReport.setCreateTimestamp(System.currentTimeMillis());
		repairManager.saveRepairReport(repairReport);
		
		/*保存使用的零件信息*/
		
		partUsage1.setRepairReport(repairReport);
		partUsage2.setRepairReport(repairReport);
		partUsage3.setRepairReport(repairReport);
		partUsage4.setRepairReport(repairReport);
		partUsage5.setRepairReport(repairReport);
		partUsage6.setRepairReport(repairReport);
		partUsage7.setRepairReport(repairReport);
		partUsage8.setRepairReport(repairReport);
		
		
		if(!StringUtils.isEmpty(partUsage1.getPartName()) && !StringUtils.isEmpty(partUsage1.getPartNo())
				&& !StringUtils.isEmpty(partUsage1.getAmount()+"") && !!StringUtils.isEmpty(partUsage1.getPrice()+"")
				&& !StringUtils.isEmpty(partUsage1.getScalar()+"")){
			repairManager.savePartUsage(partUsage1);
		}
		if(!StringUtils.isEmpty(partUsage2.getPartName()) && !StringUtils.isEmpty(partUsage2.getPartNo())
				&& !StringUtils.isEmpty(partUsage2.getAmount()+"") && !!StringUtils.isEmpty(partUsage2.getPrice()+"")
				&& !StringUtils.isEmpty(partUsage2.getScalar()+"")){
			repairManager.savePartUsage(partUsage2);
		}
		if(!StringUtils.isEmpty(partUsage3.getPartName()) && !StringUtils.isEmpty(partUsage3.getPartNo())
				&& !StringUtils.isEmpty(partUsage3.getAmount()+"") && !!StringUtils.isEmpty(partUsage3.getPrice()+"")
				&& !StringUtils.isEmpty(partUsage3.getScalar()+"")){
			repairManager.savePartUsage(partUsage3);
		}
		if(!StringUtils.isEmpty(partUsage4.getPartName()) && !StringUtils.isEmpty(partUsage4.getPartNo())
				&& !StringUtils.isEmpty(partUsage4.getAmount()+"") && !!StringUtils.isEmpty(partUsage4.getPrice()+"")
				&& !StringUtils.isEmpty(partUsage4.getScalar()+"")){
			repairManager.savePartUsage(partUsage4);
		}
		if(!StringUtils.isEmpty(partUsage5.getPartName()) && !StringUtils.isEmpty(partUsage5.getPartNo())
				&& !StringUtils.isEmpty(partUsage5.getAmount()+"") && !!StringUtils.isEmpty(partUsage5.getPrice()+"")
				&& !StringUtils.isEmpty(partUsage5.getScalar()+"")){
			repairManager.savePartUsage(partUsage5);
		}
		if(!StringUtils.isEmpty(partUsage6.getPartName()) && !StringUtils.isEmpty(partUsage6.getPartNo())
				&& !StringUtils.isEmpty(partUsage6.getAmount()+"") && !!StringUtils.isEmpty(partUsage6.getPrice()+"")
				&& !StringUtils.isEmpty(partUsage6.getScalar()+"")){
			repairManager.savePartUsage(partUsage6);
		}
		if(!StringUtils.isEmpty(partUsage7.getPartName()) && !StringUtils.isEmpty(partUsage7.getPartNo())
				&& !StringUtils.isEmpty(partUsage7.getAmount()+"") && !!StringUtils.isEmpty(partUsage7.getPrice()+"")
				&& !StringUtils.isEmpty(partUsage7.getScalar()+"")){
			repairManager.savePartUsage(partUsage7);
		}
		if(!StringUtils.isEmpty(partUsage8.getPartName()) && !StringUtils.isEmpty(partUsage8.getPartNo())
				&& !StringUtils.isEmpty(partUsage8.getAmount()+"") && !!StringUtils.isEmpty(partUsage8.getPrice()+"")
				&& !StringUtils.isEmpty(partUsage8.getScalar()+"")){
			repairManager.savePartUsage(partUsage8);
		}
		
		/*保存实施项目*/
		actualizeProject1.setRepairReport(repairReport);
		actualizeProject2.setRepairReport(repairReport);
		actualizeProject3.setRepairReport(repairReport);
		actualizeProject4.setRepairReport(repairReport);
		actualizeProject5.setRepairReport(repairReport);
		actualizeProject6.setRepairReport(repairReport);
		actualizeProject7.setRepairReport(repairReport);
		actualizeProject8.setRepairReport(repairReport);
		actualizeProject9.setRepairReport(repairReport);
		actualizeProject10.setRepairReport(repairReport);
		actualizeProject11.setRepairReport(repairReport);
		actualizeProject12.setRepairReport(repairReport);
		actualizeProject13.setRepairReport(repairReport);
		actualizeProject14.setRepairReport(repairReport);
		actualizeProject15.setRepairReport(repairReport);
		actualizeProject16.setRepairReport(repairReport);
		actualizeProject17.setRepairReport(repairReport);
		actualizeProject18.setRepairReport(repairReport);
		actualizeProject19.setRepairReport(repairReport);
		actualizeProject20.setRepairReport(repairReport);
		actualizeProject21.setRepairReport(repairReport);
		actualizeProject22.setRepairReport(repairReport);
		actualizeProject23.setRepairReport(repairReport);
		actualizeProject24.setRepairReport(repairReport);
		actualizeProject25.setRepairReport(repairReport);
		actualizeProject26.setRepairReport(repairReport);
		actualizeProject27.setRepairReport(repairReport);
		actualizeProject28.setRepairReport(repairReport);
		actualizeProject29.setRepairReport(repairReport);
		actualizeProject30.setRepairReport(repairReport);
		
		repairManager.saveActualizeProject(actualizeProject1);
		repairManager.saveActualizeProject(actualizeProject2);
		repairManager.saveActualizeProject(actualizeProject3);
		repairManager.saveActualizeProject(actualizeProject4);
		repairManager.saveActualizeProject(actualizeProject5);
		repairManager.saveActualizeProject(actualizeProject6);
		repairManager.saveActualizeProject(actualizeProject7);
		repairManager.saveActualizeProject(actualizeProject8);
		repairManager.saveActualizeProject(actualizeProject9);
		repairManager.saveActualizeProject(actualizeProject10);
		repairManager.saveActualizeProject(actualizeProject11);
		repairManager.saveActualizeProject(actualizeProject12);
		repairManager.saveActualizeProject(actualizeProject13);
		repairManager.saveActualizeProject(actualizeProject14);
		repairManager.saveActualizeProject(actualizeProject15);
		repairManager.saveActualizeProject(actualizeProject16);
		repairManager.saveActualizeProject(actualizeProject17);
		repairManager.saveActualizeProject(actualizeProject18);
		repairManager.saveActualizeProject(actualizeProject19);
		repairManager.saveActualizeProject(actualizeProject20);
		repairManager.saveActualizeProject(actualizeProject21);
		repairManager.saveActualizeProject(actualizeProject22);
		repairManager.saveActualizeProject(actualizeProject23);
		repairManager.saveActualizeProject(actualizeProject24);
		repairManager.saveActualizeProject(actualizeProject25);
		repairManager.saveActualizeProject(actualizeProject26);
		repairManager.saveActualizeProject(actualizeProject27);
		repairManager.saveActualizeProject(actualizeProject28);
		repairManager.saveActualizeProject(actualizeProject29);
		repairManager.saveActualizeProject(actualizeProject30);
		
		
		//修改下次预警时间
		
		//修改机器的计数器值
		
		//修改机器中的纸张数量(向上增加)
		
		statusTemp = true;
		
		return SUCCESS;
	}
	
	/**
	 * 查询维修单
	 * 
	 * @return
	 * @throws Exception
	 */
	public String listProtects() throws Exception{
		/*列出所有客户*/
		customers = purchaseManager.listCustomers();
		/*列出所有维修员*/
		maintenanceMen = memberManager.listPerson(2,false);//2表示维修人员
		
		if(repairReport == null){
			repairReport = new RepairReport();
		}
		
		repairReports = repairManager.pageQueryRepairReports(Common.String2Date(repairDate), repairReport.getRepairman(), repairReport.getUnitName(), null, machineNo, getCurrentPage(), pageSize);
		setTotalPage(repairReports.getTotalPageCount());
		return SUCCESS;
	}
	
	/**
	 * 查看维修单
	 * 
	 * @return
	 * @throws Exception
	 */
	public String viewProtect() throws Exception{
		return SUCCESS;
	}
	
/*=============get,set===============================================*/	
	
	public RepairReport getRepairReport() {
		return repairReport;
	}
	
	public void setRepairReport(RepairReport repairReport) {
		this.repairReport = repairReport;
	}

	public List<Customer> getCustomers() {
		return customers;
	}

	public void setCustomers(List<Customer> customers) {
		this.customers = customers;
	}

	public List<Machine> getMachines() {
		return machines;
	}

	public void setMachines(List<Machine> machines) {
		this.machines = machines;
	}

	public List<Person> getMaintenanceMen() {
		return maintenanceMen;
	}

	public void setMaintenanceMen(List<Person> maintenanceMen) {
		this.maintenanceMen = maintenanceMen;
	}

	public String getRepairDate() {
		return repairDate;
	}

	public void setRepairDate(String repairDate) {
		this.repairDate = repairDate;
	}

	public String getMachineNo() {
		return machineNo;
	}

	public void setMachineNo(String machineNo) {
		this.machineNo = machineNo;
	}

	public PartUsage getPartUsage1() {
		return partUsage1;
	}

	public void setPartUsage1(PartUsage partUsage1) {
		this.partUsage1 = partUsage1;
	}

	public PartUsage getPartUsage2() {
		return partUsage2;
	}

	public void setPartUsage2(PartUsage partUsage2) {
		this.partUsage2 = partUsage2;
	}

	public PartUsage getPartUsage3() {
		return partUsage3;
	}

	public void setPartUsage3(PartUsage partUsage3) {
		this.partUsage3 = partUsage3;
	}

	public PartUsage getPartUsage4() {
		return partUsage4;
	}

	public void setPartUsage4(PartUsage partUsage4) {
		this.partUsage4 = partUsage4;
	}

	public PartUsage getPartUsage5() {
		return partUsage5;
	}

	public void setPartUsage5(PartUsage partUsage5) {
		this.partUsage5 = partUsage5;
	}

	public PartUsage getPartUsage6() {
		return partUsage6;
	}

	public void setPartUsage6(PartUsage partUsage6) {
		this.partUsage6 = partUsage6;
	}

	public PartUsage getPartUsage7() {
		return partUsage7;
	}

	public void setPartUsage7(PartUsage partUsage7) {
		this.partUsage7 = partUsage7;
	}

	public PartUsage getPartUsage8() {
		return partUsage8;
	}

	public void setPartUsage8(PartUsage partUsage8) {
		this.partUsage8 = partUsage8;
	}

	public ActualizeProject getActualizeProject1() {
		return actualizeProject1;
	}

	public void setActualizeProject1(ActualizeProject actualizeProject1) {
		this.actualizeProject1 = actualizeProject1;
	}

	public ActualizeProject getActualizeProject2() {
		return actualizeProject2;
	}

	public void setActualizeProject2(ActualizeProject actualizeProject2) {
		this.actualizeProject2 = actualizeProject2;
	}

	public ActualizeProject getActualizeProject3() {
		return actualizeProject3;
	}

	public void setActualizeProject3(ActualizeProject actualizeProject3) {
		this.actualizeProject3 = actualizeProject3;
	}

	public ActualizeProject getActualizeProject4() {
		return actualizeProject4;
	}

	public void setActualizeProject4(ActualizeProject actualizeProject4) {
		this.actualizeProject4 = actualizeProject4;
	}

	public ActualizeProject getActualizeProject5() {
		return actualizeProject5;
	}

	public void setActualizeProject5(ActualizeProject actualizeProject5) {
		this.actualizeProject5 = actualizeProject5;
	}

	public ActualizeProject getActualizeProject6() {
		return actualizeProject6;
	}

	public void setActualizeProject6(ActualizeProject actualizeProject6) {
		this.actualizeProject6 = actualizeProject6;
	}

	public ActualizeProject getActualizeProject7() {
		return actualizeProject7;
	}

	public void setActualizeProject7(ActualizeProject actualizeProject7) {
		this.actualizeProject7 = actualizeProject7;
	}

	public ActualizeProject getActualizeProject8() {
		return actualizeProject8;
	}

	public void setActualizeProject8(ActualizeProject actualizeProject8) {
		this.actualizeProject8 = actualizeProject8;
	}

	public ActualizeProject getActualizeProject9() {
		return actualizeProject9;
	}

	public void setActualizeProject9(ActualizeProject actualizeProject9) {
		this.actualizeProject9 = actualizeProject9;
	}

	public ActualizeProject getActualizeProject10() {
		return actualizeProject10;
	}

	public void setActualizeProject10(ActualizeProject actualizeProject10) {
		this.actualizeProject10 = actualizeProject10;
	}

	public ActualizeProject getActualizeProject11() {
		return actualizeProject11;
	}

	public void setActualizeProject11(ActualizeProject actualizeProject11) {
		this.actualizeProject11 = actualizeProject11;
	}

	public ActualizeProject getActualizeProject12() {
		return actualizeProject12;
	}

	public void setActualizeProject12(ActualizeProject actualizeProject12) {
		this.actualizeProject12 = actualizeProject12;
	}

	public ActualizeProject getActualizeProject13() {
		return actualizeProject13;
	}

	public void setActualizeProject13(ActualizeProject actualizeProject13) {
		this.actualizeProject13 = actualizeProject13;
	}

	public ActualizeProject getActualizeProject14() {
		return actualizeProject14;
	}

	public void setActualizeProject14(ActualizeProject actualizeProject14) {
		this.actualizeProject14 = actualizeProject14;
	}

	public ActualizeProject getActualizeProject15() {
		return actualizeProject15;
	}

	public void setActualizeProject15(ActualizeProject actualizeProject15) {
		this.actualizeProject15 = actualizeProject15;
	}

	public ActualizeProject getActualizeProject16() {
		return actualizeProject16;
	}

	public void setActualizeProject16(ActualizeProject actualizeProject16) {
		this.actualizeProject16 = actualizeProject16;
	}

	public ActualizeProject getActualizeProject17() {
		return actualizeProject17;
	}

	public void setActualizeProject17(ActualizeProject actualizeProject17) {
		this.actualizeProject17 = actualizeProject17;
	}

	public ActualizeProject getActualizeProject18() {
		return actualizeProject18;
	}

	public void setActualizeProject18(ActualizeProject actualizeProject18) {
		this.actualizeProject18 = actualizeProject18;
	}

	public ActualizeProject getActualizeProject19() {
		return actualizeProject19;
	}

	public void setActualizeProject19(ActualizeProject actualizeProject19) {
		this.actualizeProject19 = actualizeProject19;
	}

	public ActualizeProject getActualizeProject20() {
		return actualizeProject20;
	}

	public void setActualizeProject20(ActualizeProject actualizeProject20) {
		this.actualizeProject20 = actualizeProject20;
	}

	public ActualizeProject getActualizeProject21() {
		return actualizeProject21;
	}

	public void setActualizeProject21(ActualizeProject actualizeProject21) {
		this.actualizeProject21 = actualizeProject21;
	}

	public ActualizeProject getActualizeProject22() {
		return actualizeProject22;
	}

	public void setActualizeProject22(ActualizeProject actualizeProject22) {
		this.actualizeProject22 = actualizeProject22;
	}

	public ActualizeProject getActualizeProject23() {
		return actualizeProject23;
	}

	public void setActualizeProject23(ActualizeProject actualizeProject23) {
		this.actualizeProject23 = actualizeProject23;
	}

	public ActualizeProject getActualizeProject24() {
		return actualizeProject24;
	}

	public void setActualizeProject24(ActualizeProject actualizeProject24) {
		this.actualizeProject24 = actualizeProject24;
	}

	public ActualizeProject getActualizeProject25() {
		return actualizeProject25;
	}

	public void setActualizeProject25(ActualizeProject actualizeProject25) {
		this.actualizeProject25 = actualizeProject25;
	}

	public ActualizeProject getActualizeProject26() {
		return actualizeProject26;
	}

	public void setActualizeProject26(ActualizeProject actualizeProject26) {
		this.actualizeProject26 = actualizeProject26;
	}

	public ActualizeProject getActualizeProject27() {
		return actualizeProject27;
	}

	public void setActualizeProject27(ActualizeProject actualizeProject27) {
		this.actualizeProject27 = actualizeProject27;
	}

	public ActualizeProject getActualizeProject28() {
		return actualizeProject28;
	}

	public void setActualizeProject28(ActualizeProject actualizeProject28) {
		this.actualizeProject28 = actualizeProject28;
	}

	public ActualizeProject getActualizeProject29() {
		return actualizeProject29;
	}

	public void setActualizeProject29(ActualizeProject actualizeProject29) {
		this.actualizeProject29 = actualizeProject29;
	}

	public ActualizeProject getActualizeProject30() {
		return actualizeProject30;
	}

	public void setActualizeProject30(ActualizeProject actualizeProject30) {
		this.actualizeProject30 = actualizeProject30;
	}

	public DataPage<RepairReport> getRepairReports() {
		return repairReports;
	}

	public void setRepairReports(DataPage<RepairReport> repairReports) {
		this.repairReports = repairReports;
	}
	
	
	
}
